package Boot.test.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

// 获取请求或者响应体中的值
public class Request {
    public Map<String, String> Axios(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        String requestURI = request.getRequestURI();
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = request.getHeader(key);
            map.put(key, value);
        }
        map.put("url", requestURI); //添加请求的url
        return map;
    }

    public Collection<String> AxiosResponse(HttpServletResponse response) {
        Map<String, String> map = new HashMap<String, String>();
        Collection<String> headerNames = response.getHeaderNames();

        return headerNames;
    }
}
